package my.senix.sc.config;

import my.senix.sc.servlet.MyServlet;
import my.senix.sc.servlet.MyWebFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by lhs on 2018/11/26.
 */
@Configuration
public class MyServletFilterRegistry {

    @Bean
    public ServletRegistrationBean myServlet(@Value("${servlet.param.addr:default}") String addr){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setName("my-servlet");
        registrationBean.setServlet(new MyServlet());
        registrationBean.addUrlMappings("/senix/*");
        registrationBean.setLoadOnStartup(1);
        registrationBean.addInitParameter("addr",addr);

        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean myFilter() {

        FilterRegistrationBean registrationBean=new FilterRegistrationBean();
        registrationBean.setName("my-filter");
        registrationBean.setFilter(new MyWebFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("exclusions",  "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");

        return registrationBean;
    }

}
